package mo.golden;

import java.util.Stack;

public class L03_02 {

    private Stack<Integer> elements = new Stack<>();
    private Stack<Integer> min = new Stack<>();

    public void push(int x) {
        elements.push(x);
        if (min.isEmpty()) {
            min.push(x);
        } else {
            if (x < min.peek()) {
                min.push(x);
            } else {
                min.push(min.peek());
            }
        }
    }

    public void pop() {
        elements.pop();
        min.pop();
    }

    public int top() {
        return elements.peek();
    }

    public int getMin() {
        return min.peek();
    }

}
